package com.lancoo.answer.view.result

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.answer.databinding.EvAdapterAnswersheetChildBinding
import com.lancoo.answer.databinding.EvAdapterAnswersheetParentBinding
import com.lancoo.answer.model.bean.SameQuesDetail
import com.lancoo.answer.view.base.XBaseRecyclerAdapter
import com.lancoo.answer.view.base.XBaseRecyclerHolder

/**
 * auther: 王国龙
 *  Date：2020.06.15
 * describe:
 */
class SameAnswerSheetParentAdapter(
    val sameQuesDetail: SameQuesDetail,
    private val recommendState: Int
) : XBaseRecyclerAdapter<EvAdapterAnswersheetParentBinding>() {

    override fun onBindingView(viewGroup: ViewGroup?): EvAdapterAnswersheetParentBinding {
        return EvAdapterAnswersheetParentBinding.inflate(
            LayoutInflater.from(
                viewGroup!!.context
            ), viewGroup, false
        )
    }

    override fun onBindingData(
        holder: XBaseRecyclerHolder<EvAdapterAnswersheetParentBinding>,
        position: Int
    ) {
        holder.viewBinding.TvTypeInfor.visibility = View.GONE

        val adapterChild = SameAnswerSheetChildAdapter(
             sameQuesDetail, recommendState
        )
        holder.viewBinding.RvAnswerSheetChild.adapter = adapterChild
        adapterChild.setClickChildListener(object :
            SameAnswerSheetChildAdapter.OnClickChildListener {
            override fun onClick(sortIndex: String) {
                clickParentListener!!.onClick(sortIndex)
            }

        })
    }

    override fun getItemCount(): Int {
        return 1
    }

    interface OnClickParentListener {
        fun onClick(sortIndex: String)
    }

    private var clickParentListener: OnClickParentListener? = null

    fun setClickParentListener(clickParentListener: OnClickParentListener?) {
        this.clickParentListener = clickParentListener
    }

}